package com.jushu.storbox.view.dialog;

import android.app.ActionBar.LayoutParams;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

import com.jushu.storbox.R;
import com.jushu.storbox.ShareDriveApplication;
import com.jushu.storbox.constant.ClientConfig;
import com.jushu.storbox.entities.FileFolderInfo;
import com.jushu.storbox.network.WifiController;
import com.jushu.storbox.util.PublicTools;

public class DownloadDialogWithCheckWifi {

	public final void download(Context context, final FileFolderInfo info) {
		WifiController wifiController = ShareDriveApplication.getInstance().getWifiController();
		if (!wifiController.getNetworkState()) {
            Toast.makeText(context, R.string.clouddrive_mode_without_internet,
                Toast.LENGTH_SHORT).show();
        } else {
        	if (ClientConfig.NETWORK_ISWIFI.equals(wifiController.getWifiType())
                || !PublicTools.getDownloadRemind(context)) {
        		executeDownloadTask(info);
            } else {
                final ClouddriveDialog menuDialog = new ClouddriveDialog(context,
                    R.style.myDialogTheme, R.layout.window_wifi_dialog);
                menuDialog.setHeigth(LayoutParams.MATCH_PARENT);
                menuDialog.setWidth(LayoutParams.MATCH_PARENT);
                menuDialog.setCanceledOnTouchOutside(true);
                menuDialog.show();
                View conventView = menuDialog.getConventView();
                Button confirmBt = (Button) conventView.findViewById(R.id.confirm_btn);
                
                confirmBt.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
						menuDialog.dismiss();
                    	executeDownloadTask(info);
                    }
                });
                Button cancleBt = (Button) conventView.findViewById(R.id.cancle_btn);
                cancleBt.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        menuDialog.dismiss();
                    }
                });
            }
        }
	}

	protected void executeDownloadTask(FileFolderInfo info) {
		
	}
}
